package cn.topcodes.tcsf.cms.utils;

import java.io.*;

/**
 * Created by yvan
 * Author: Yvan
 * Date: 2017/12/29
 * Time: 上午10:05
 **/
public class FileUtils {

    public static String readFile(String path) throws IOException {

        StringBuilder builder = new StringBuilder();

        try {

            InputStreamReader reader = new InputStreamReader(new FileInputStream(path), "UTF-8");
            BufferedReader bfReader = new BufferedReader(reader);

            String tmpContent = null;

            while ((tmpContent = bfReader.readLine()) != null) {
                builder.append(tmpContent);
            }

            bfReader.close();

        } catch (UnsupportedEncodingException e) {
            // 忽略
        }

        return filter(builder.toString());
    }

    // 过滤输入字符串, 剔除多行注释以及替换掉反斜杠
    public static String filter(String input) {
        return input.replaceAll("/\\*[\\s\\S]*?\\*/", "");
    }
}
